// Set working directory and import data file
cd "/Users/gabriellelevy/OneDrive - Dartmouth College/Replication Files/Narang - Duration Model"
clear
import excel using levy_narang.xlsx, firstrow 

//REPLICATING NARANG RESULTS
stset t1, id(warnumber) failure(warend) enter(t0) 

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if pcw==1 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if pcw==0 
//This code replicates Narang's results perfectly. 


//ADDING NEW VARIABLES
//converting added variables from strings to numbers
destring epr_exclpop, replace
destring epr_discrimpop, replace
destring epr_nstar, replace
destring ethnic_war, replace
destring hief_ef, replace
destring v2x_corr,replace
destring capacity, replace

sum epr_exclpop epr_discrimpop epr_nstar ethnic_war hief_ef v2x_corr capacity


//NSTAR SUBSET ANALYSIS (data for Table 2)
sum epr_nstar, d
kdensity epr_nstar

cumul epr_nstar, gen(nstar_pctl) equal

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl<0.4 & nstar_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl>0.4 & nstar_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl<0.5 & nstar_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl>0.5 & nstar_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl<0.6 & nstar_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl>0.6 & nstar_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl<0.7 & nstar_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl>0.7 & nstar_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl<0.8 & nstar_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if nstar_pctl>0.8 & nstar_pctl!=.


//ETHNIC WAR SUBSET ANALYSIS (data for Table 2)
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests // original

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if ethnic_war==0

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if ethnic_war==1


//SUBSET ANALYSES FOR ADDITIONAL ETHNIC DIVIDES VARIABLES (exclpop, discrimpop, hief)
//exclpop (data for Table B4)
sum epr_exclpop, d
kdensity epr_exclpop

cumul epr_exclpop, gen(exclpop_pctl) equal

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl<0.4 & exclpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl>0.4 & exclpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl<0.5 & exclpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl>0.5 & exclpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl<0.6 & exclpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl>0.6 & exclpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl<0.7 & exclpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl>0.7 & exclpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl<0.8 & exclpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if exclpop_pctl>0.8 & exclpop_pctl!=.

//discrimpop (data for Table B7)
sum epr_discrimpop, d
kdensity epr_discrimpop

cumul epr_discrimpop, gen(discrimpop_pctl) equal

//stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl<0.4 & discrimpop_pctl!=. //insufficient data
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl>0.4 & discrimpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl<0.5 & discrimpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl>0.5 & discrimpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl<0.6 & discrimpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl>0.6 & discrimpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl<0.7 & discrimpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl>0.7 & discrimpop_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl<0.8 & discrimpop_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if discrimpop_pctl>0.8 & discrimpop_pctl!=.

//hief (data for Table B10)
sum hief_ef, d
kdensity hief_ef

cumul hief_ef, gen(hief_pctl) equal

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl<0.4 & hief_pctl!=. 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl>0.4 & hief_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl<0.5 & hief_pctl!=. 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl>0.5 & hief_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl<0.6 & hief_pctl!=. 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl>0.6 & hief_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl<0.7 & hief_pctl!=. 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl>0.7 & hief_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl<0.8 & hief_pctl!=. 
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if hief_pctl>0.8 & hief_pctl!=.



//CORRUPTION SUBSET ANALYSIS (data for Table 3)
cumul v2x_corr, gen(corr_pctl) equal

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl<0.4 & corr_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl>0.4 & corr_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl<0.5 & corr_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl>0.5 & corr_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl<0.6 & corr_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl>0.6 & corr_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl<0.7 & corr_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl>0.7 & corr_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl<0.8 & corr_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if corr_pctl>0.8 & corr_pctl!=.


//STATE CAPACITY SUBSET ANALYSIS (data for Table 4)
cumul capacity, gen(capacity_pctl) equal

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl<0.4 & capacity_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl>0.4 & capacity_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl<0.5 & capacity_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl>0.5 & capacity_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl<0.6 & capacity_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl>0.6 & capacity_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl<0.7 & capacity_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl>0.7 & capacity_pctl!=.

stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl<0.8 & capacity_pctl!=.
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests if capacity_pctl>0.8 & capacity_pctl!=.


//INTERACTION ANALYSES 
//Table A1: Narang - Ethnic Divides Interaction Analysis
//original
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests 
outreg2 using tableA1.doc, replace eform append ctitle(Original)
//nstar
gen nstar_x_aid=epr_nstar*aidlog 
kdensity nstar_x_aid
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests  nstar_x_aid epr_nstar
outreg2 using tableA1.doc, eform append ctitle(Nstar)
//ethnic war
gen ethnic_war_x_aid=ethnic_war*aidlog
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests ethnic_war_x_aid ethnic_war
outreg2 using tableA1.doc, eform append ctitle(Ethnic War)

//Table B1: Narang – Ethnic Divides Interaction Analysis (full)
//original
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests 
outreg2 using tableB1.doc, replace eform append ctitle(Original)
//ethnic war
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests ethnic_war_x_aid ethnic_war
outreg2 using tableB1.doc, eform append ctitle(Ethnic War)
//nstar
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests  nstar_x_aid epr_nstar
outreg2 using tableB1.doc, eform append ctitle(Nstar)
//other variables
//exclpop
gen exclpop_x_aid=epr_exclpop*aidlog
kdensity exclpop_x_aid
stcox   aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests exclpop_x_aid epr_exclpop
outreg2 using tableB1.doc, eform append ctitle(Exclpop)
//discrimpop
gen discrimpop_x_aid=epr_discrimpop*aidlog
kdensity discrimpop_x_aid
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests discrimpop_x_aid epr_discrimpop 
outreg2 using tableB1.doc, eform append ctitle(Discrimpop) 
//hief
gen hief_x_aid=hief_ef*aidlog
kdensity hief_x_aid
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests  hief_x_aid hief_ef
outreg2 using tableB1.doc, eform append ctitle(Hief) 


//Table A2: Narang – Corruption Interaction Analysis
//original
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests 
outreg2 using tableA2.doc, replace eform append ctitle(Original)
//v2x_corr
gen corr_x_aid=v2x_corr*aidlog 
kdensity corr_x_aid
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests  corr_x_aid v2x_corr
outreg2 using tableA2.doc, eform append ctitle(v2x_corr)


//Table A3: Narang – State Capacity Interaction Analysis
//original
stcox aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests 
outreg2 using tableA3.doc, replace eform append ctitle(Original)
//v2x_corr
gen capacity_x_aid=capacity*aidlog 
kdensity capacity_x_aid
stcox  aidlog bdeadbestlag logpop gdppc polity2 diamonds drugs resources guarantee mountains forests  capacity_x_aid capacity
outreg2 using tableA3.doc, eform append ctitle(capacity)






